package org.clockworkmages.games.anno1186;

import org.clockworkmages.games.anno1186.gui.AnimatedImage;

public class GameTimeService implements TimeConstants {

	@Injected
	private GameStateService gameStateService;

	@Injected
	private GameGuiService gameGuiService;

	// @Inject
	// private GameCharacterService gameCharacterService;

	public void advanceTime(long timePassed) {
		GameState gameState = gameStateService.getGameState();
		long newTime = gameState.getTime() + timePassed;
		gameState.setTime(newTime);

		AnimatedImage sunImage = gameGuiService.getTextPane().getSunImage();
		AnimatedImage moonImage = gameGuiService.getTextPane().getMoonImage();
		double targetSunState = new Double((newTime + 1.5 * HOUR) % DAY) / DAY;
		double targetMoonState = targetSunState - 0.5;
		while (targetSunState < sunImage.getState()) {
			targetSunState = targetSunState + 1;
		}
		while (targetMoonState < moonImage.getState()) {
			targetMoonState = targetMoonState + 1;
		}
		sunImage.setTargetState(targetSunState,
				(targetSunState - sunImage.getState()) * 7000);
		moonImage.setTargetState(targetMoonState,
				(targetMoonState - moonImage.getState()) * 7000);

		// called in SituationService:
		// if (gameState.getCharacter().isStatsAreStale()) {
		// gameCharacterService.refreshStats(gameState.getCharacter());
		// }
		// if (gameStateService.isCombat()) {
		// if (gameState.getEnemy().isStatsAreStale()) {
		// gameCharacterService.refreshStats(gameState.getEnemy());
		// }
		// }
		// gameGuiService.getStatsPane().repaint();
	}
}
